import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { TabsPage } from '../pages/tabs/tabs';
import { LoginPage } from '../pages/login/login';
import { ParkDataProvider } from '../providers/park-data/park-data';
import { Storage } from '@ionic/storage';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  // rootPage:any = TabsPage;
  // rootPage: any = LoginPage;
  rootPage:any;

  constructor(
    platform: Platform, 
    statusBar: StatusBar, 
    splashScreen: SplashScreen,
    parkDataProvider:ParkDataProvider,
    storage:Storage) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
      parkDataProvider.setParksToCache();
      storage.ready().then(()=>{
        storage.remove('LOGIN_INFO');
        storage.get('USER_INFO').then((value:string)=>{
          let remember = !!value ? JSON.parse(value).remember:false;
          if (remember) {
            this.rootPage = TabsPage;
            storage.set('LOGIN_INFO',value);
          }else{
            this.rootPage = LoginPage;
          }
        });
      });
    });
  }
}
